package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMajor;
import com.ruoyi.system.service.ITMajorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 院Controller
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/system/major")
public class TMajorController extends BaseController
{
    @Autowired
    private ITMajorService tMajorService;


    @GetMapping("/all")
    public List<TMajor> getAll(){
        return tMajorService.getAll();
    }

    /**
     * 查询院列表
     */
    @PreAuthorize("@ss.hasPermi('system:major:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMajor tMajor)
    {
        startPage();
        List<TMajor> list = tMajorService.selectTMajorList(tMajor);
        return getDataTable(list);
    }

    /**
     * 导出院列表
     */
    @PreAuthorize("@ss.hasPermi('system:major:export')")
    @Log(title = "院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMajor tMajor)
    {
        List<TMajor> list = tMajorService.selectTMajorList(tMajor);
        ExcelUtil<TMajor> util = new ExcelUtil<TMajor>(TMajor.class);
        util.exportExcel(response, list, "院数据");
    }

    /**
     * 获取院详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:major:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tMajorService.selectTMajorById(id));
    }

    /**
     * 新增院
     */
    @PreAuthorize("@ss.hasPermi('system:major:add')")
    @Log(title = "院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMajor tMajor)
    {
        return toAjax(tMajorService.insertTMajor(tMajor));
    }

    /**
     * 修改院
     */
    @PreAuthorize("@ss.hasPermi('system:major:edit')")
    @Log(title = "院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMajor tMajor)
    {
        return toAjax(tMajorService.updateTMajor(tMajor));
    }

    /**
     * 删除院
     */
    @PreAuthorize("@ss.hasPermi('system:major:remove')")
    @Log(title = "院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMajorService.deleteTMajorByIds(ids));
    }
}
